home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3428 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: newbie--what's wrong with this?
  5. Date: Sun, 28 Jan 96 22:27:34 GMT
  6. Organization: none
  7. Message-ID: <822868054snz@genesis.demon.co.uk>
  8. References: <4ee8gk$kes@shiva.usa.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4ee8gk$kes@shiva.usa.net> jhamp@earth.usa.net "James Hamp" writes:
  15.  
  16. >Rule->CompRule = (COMPARERULE *)malloc(2 * sizeof(COMPARERULE));
  17. >
  18. >/* Initialize first compare rule, then... */
  19. >
  20. >Rule->CompRule++;
  21. >^^^^^^^^^^^^^^^^^   This didn't work--when I initialized the second rule
  22. >                    (or so I thought), it went into the first rule.
  23.  
  24. Actually it did work except that it did more than you expected. This
  25. increments Rule->CompRule and therefore makes that point to the second rule.
  26. To access the first rule using the pointer you would then need something
  27. like Rule->CompRule[-1] and to access the 2nd you need Rule->CompRule[0].
  28.  
  29. >Thinking I had a precedence problem, I tried
  30. >
  31. >(Rule->CompRule)++;
  32. >and the same thing happened.
  33.  
  34. Right - that means the same thing.
  35.  
  36. >I know I'm being stupid here--my try that worked was
  37. >to initialize the second rule with Rule->CompRule[1].members.  Since I 
  38. >made it work, the code's okay, but I'd like to know what I'm not under-
  39. >standing.
  40.  
  41. Right, that simply accesses/updates the 2nd entry without changing the
  42. pointer. Therefore future uses of that pointer worked as you expected.
  43.  
  44. -- 
  45. -----------------------------------------
  46. Lawrence Kirby | fred@genesis.demon.co.uk
  47. Wilts, England | 70734.126@compuserve.com
  48. -----------------------------------------
  49.